﻿using System;
using System.Collections.Generic;
using System.Xml;
using System.Drawing;
using System.Xml.Serialization;
using rlTodayMakeSkin.Project.XmlElement.XmlSubElements;
using rlTodayMakeSkin.Project.Attributes;

namespace rlTodayMakeSkin.Project.XmlElement
{
    /// <summary>
    /// class that represents a xml element who can contain
    /// sub xml elements
    /// </summary>
    [Serializable]
    abstract public class ContainerSubElements : rlTodayXmlElement
    {
        private XmlNodeList subElementsNode=null;
        private OnClick on_click = null;
        private rlFont elementFont = null;
        private HourHand hh = null;

        protected ContainerSubElements(XmlNode nodo, rlTodayProject p)
            : base(nodo.Attributes, p)
        {
            listaAtt = nodo.Attributes;
            subElementsNode = nodo.ChildNodes;
            initSubElements();
        }

        protected ContainerSubElements(rlTodayProject p) : base(p) 
        {
            font = new rlFont(this);
            onclick = new OnClick(this);
            hh = new HourHand(this);
        }

        protected ContainerSubElements() { } //for the serialization


        /// <summary>
        /// Sets, gets font property of this elmement
        /// </summary>
        [CompositePropertyAttribute("font sub element", typeof(rlFont))]
        [System.Xml.Serialization.XmlElement("Font", Type = typeof(rlFont),IsNullable=false)]
        public rlFont font
        {
            get { return elementFont; }
            set { elementFont = value; }
        }

        /// <summary>
        /// Gets, sets the OnClick property of this elmement
        /// </summary>
        [CompositePropertyAttribute("OnClick sub element", typeof(rlFont))]
        [System.Xml.Serialization.XmlElement("OnClick", Type = typeof(OnClick),IsNullable=false)]
        public OnClick onclick
        {
            get { return on_click; }
            set { on_click = value; }
        }

        /// <summary>
        /// Gets, sets font property of this elmement
        /// </summary>
        [CompositePropertyAttribute("HourHand sub element", typeof(rlFont))]
        [System.Xml.Serialization.XmlElement("HourHand", Type = typeof(HourHand), IsNullable=false)]
        public HourHand hourHand
        {
            get { return hh; }
            set { hh = value; }
        }

        /// <summary>
        /// Sets the name of the font
        /// </summary>
        /// <remarks>Required by PropertyWindow class</remarks>
        public string FontName
        {
            set
            {
                font.FontName = value;
            }
        }

        /// <summary>
        /// Sets the size of the font
        /// </summary>
        /// <remarks>Required by PropertyWindow class</remarks>
        public int Size
        {
            set { font.Size = value;}
        }

        /// <summary>
        /// Sets the weigth of the font
        /// </summary>
        /// <remarks>Required by PropertyWindow class</remarks>
        public string Weight
        {
            set { font.Weight = value; }
        }

        /// <summary>
        /// Sets the on click command 
        /// </summary>
        /// <remarks>Required by PropertyWindow class</remarks>
        public string OnClickCommand
        {
            set { on_click.OnClickCommand = value; }
        }

        /// <summary>
        /// Sets the on click file property
        /// </summary>
        /// <remarks>Required by PropertyWindow class</remarks>
        public string OnClickFile
        {
            set { on_click.OnClickFile = value; }
        }

        /// <summary>
        /// Sets show property for HourHand sub element
        /// </summary>
        /// <remarks>Required by PropertyWindow class</remarks>
        public bool Show
        {
            set { hh.Show = value; }
        }

        /// <summary>
        /// Sets Source property for HourHand sub element
        /// </summary>
        /// <remarks>Required by PropertyWindow class</remarks>
        public string Source
        {
            set { hh.Source = value; }
        }

        /// <summary>
        /// Sets color property for HourHand sub element
        /// </summary>
        /// <remarks>Required by PropertyWindow class</remarks>
        public Color HourHandColor
        {
            set { hh.HourHandColor = value; }
        }


        /// <summary>
        /// Read and initialize sub elements of this node
        /// </summary>
        protected void initSubElements()
        {
            for (int i = 0; i < subElementsNode.Count; i++)
            {
                switch (subElementsNode[i].Name)
                {
                    case "OnClick":
                        onclick = new OnClick(subElementsNode[i].Attributes, this);
                        break;
                    case "Font":
                        elementFont = new rlFont(subElementsNode[i].Attributes, this);
                        break;
                    case "HourHand":
                        hh = new HourHand(subElementsNode[i].Attributes, this);
                        break;
                }
            }
            if (onclick == null) onclick = new OnClick(this);
            if (elementFont == null) elementFont = new rlFont(this);
            if (hh == null) hh = new HourHand(this);
        }
    } //end class
}// end namspace
